/**
 * 加载树
 * 
 * @class treeload
 * @extends Ext.tree.TreeLoader
 */
enterprisetreeload = Ext.extend(Ext.tree.TreeLoader, {
			constructor : function() {
				enterprisetreeload.superclass.constructor.call(this, {
							url : 'cxxqysjsb/getcxxqysjsbpaneltree.action',// center中的数初始化
							requestMethod : 'GET'
						});
			}
		});
/**
 * 形成的树结构
 * 
 * @class enterpriseleftnav
 * @extends Ext.tree.TreePanel
 */
enterpriseleftnav = Ext.extend(Ext.tree.TreePanel, {
	tree : null,
	constructor : function() {
		this.tree = new enterprisetreeload();
		enterpriseleftnav.superclass.constructor.call(this, {
			title : '企业数据申报填写目录',
			iconCls : 'homeTab',
			region : 'west',
			bodyStyle : 'padding:15px',
			collapsible : true,
			split : true,
			width : 200,
			containerScroll : true,
			animate : true,
			autoScroll : true,
			collapsible : true,
			margins : '3 0 0 0',
			rootVisible : false,
			loader : this.tree,
			root : new Ext.tree.AsyncTreeNode({
						id : '0',
						text : '申报项目',
						iconCls : 'tree'
					}),
			bbar : ['->', '-', {
				text : '提交',
				iconCls : 'itemadd',
				scope : this,
				handler : function() {
					Ext.Msg.show({
						title : '提示',
						msg : '你确定完成全部数据的填写了吗？申报之后数据将不能进行修改',
						icon : Ext.Msg.QUESTION,
						buttons : Ext.Msg.OKCANCEL,
						fn : function(btn) {
							if (btn == 'ok') {
								Ext.Ajax.request({
									url : 'cxxqysjsb/updateenterprisestate.action',
									scope : this,
									params : {
										uid : userId,
										type : OPTION_DATA_TYPE,
										year : OPTION_NDDECLARE_YEAR
									},
									success : function(response, options) {
										if (response.responseText == 'ok') {
											Ext.Msg
													.alert('提示',
															'&nbsp&nbsp&nbsp&nbsp&nbsp数据提交成功&nbsp&nbsp&nbsp&nbsp');
										} else {

											Ext.Msg.alert('提示', '服务器返回错误');
										}

									}
								});
							} else if (btn == 'cancel') {
								return;
							}
						}
					});
				}
			}]
		});
		this.addEvents('newtab'); // 添加新的事件，如果点击树抛出在center中新加入一个newtab
		this.on('click', this.clickTree, this);
	},
	clickTree : function(_node) {
		this.fireEvent('newtab', _node);
	}
});
/**
 * 说明信息
 * 
 * @class tabcom
 * @extends Ext.Panel
 */
tabcom = Ext.extend(Ext.Panel, {
			constructor : function() {
				tabcom.superclass.constructor.call(this, {
							title : '数据申报填写说明',
							id : 'docs',
							iconCls : "homeTab",
							bodyStyle : 'padding:10px',
							autoLoad : 'datainput.html',
							layout : 'fit'
						})
			}
		});
/**
 * 形成规定的tab
 * 
 * @class enterprisetabbody
 * @extends Ext.TabPanel
 */
enterprisetabbody = Ext.extend(Ext.TabPanel, {
			t : null,
			constructor : function() {
				this.t = new tabcom();
				enterprisetabbody.superclass.constructor.call(this, {
							region : 'center',
							margins : '0 5 0 0',
							activeTab : 0,
							enableTabScroll : true,
							autoScroll : true,
							items : [this.t],
							plugins : new Ext.ux.TabCloseMenu()
						})

			},
			tabCliskTree : function(_node) {
				if (!_node.isLeaf()) {
					return false;
				}
				var id = _node.id;
				var tab = Ext.getCmp(id);
				var cls = _node.attributes['iconCls'];
				if (!tab) {
					tab = this.add(new Ext.Panel({
								id : id,//
								title : _node.text,
								layout : 'fit',
								iconCls : cls,
								closable : true
							}));
					this.setActiveTab(tab);
					this.loadModel(_node.id, tab);
				} else {
					this.setActiveTab(tab);
				}
			},
			loadModel : function(id, tab) {
				var model;
				if (this[id]) {
					model = new this[id](tab);
				} else {
					// this.loadmask.show();
					Ext.Ajax.request({
								method : 'GET',
								url : 'js/cxxqysjsb/' + id + '.js',
								scope : this,
								success : function(response) {
									this[id] = eval(response.responseText);
									model = new this[id](tab);
									// this.loadMask.hide();
								}
							})
				}
			}
		});
cxxqysjsballpanel = Ext.extend(Ext.Panel, {
			tree : null,
			tab : null,
			constructor : function() {
				this.tree = new enterpriseleftnav();
				this.tab = new enterprisetabbody();
				cxxqysjsballpanel.superclass.constructor.call(this, {
							layout : 'border',
							defaults : {
								split : true
							},
							items : [this.tree, this.tab]

						});
				this.tree.on('newtab', function(_node) {
							this.tab.tabCliskTree(_node);
						}, this);

			}
		});
/**
 * 如果日期不符，则进行这个面板的组装
 * 
 * @class outoftimerange_panel 时间超出范围的面板
 * @extends Ext.Panel
 */
outoftimerange_panel = Ext.extend(Ext.Panel, {
			cfg : null,
			constructor : function(_cfg) {
				this.cfg = _cfg;
				outoftimerange_panel.superclass.constructor.call(this, {
							title : this.cfg.title,
							html : '<font color="red" size=6>' + this.cfg.msg
									+ '</font>'
						})
			}
		});
/**
 * 页面组装面板
 * 
 * @class
 * @extends demo.module
 */
Ext.extend(demo.module, {
			init : function() {
//				 if (serverdate > OPTION_NDDECLARE_END_DATE) {
//				 var cfg = {
//				 title : '申报时间已过',
//				 msg : '申报时间已过，您现在不能申报数据'
//				 }
//				 this.body = new outoftimerange_panel(cfg);
//				 this.main.add(this.body);
//				 this.main.doLayout();
//				 } else if (serverdate > OPTION_NDDECLARE_END_DATE) {
//				 var cfg = {
//				 title : '申报时间未到',
//				 msg : '申报时间未到，您现在不能申报数据'
//				 }
//				 this.body = new outoftimerange_panel(cfg);
//				 this.main.add(this.body);
//				 this.main.doLayout();
//				 } else {
//				 var body = new cxxqysjsballpanel();
//				 this.main.add(body);
//				 this.main.doLayout();
//				 }
				var body = new cxxqysjsballpanel();
				this.main.add(body);
				this.main.doLayout();
			}
		});